package com.crm.custinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.StatusConstant;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.crm.custinfo.domain.CustNoticeInfo;
import com.crm.custinfo.service.ICustNoticeInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 备忘录Controller
 * 
 * @author ruoyi
 * @date 2024-01-12
 */
@RestController
@RequestMapping("/crmsys/notice")
public class CustNoticeInfoController extends BaseController
{
    @Autowired
    private ICustNoticeInfoService custNoticeInfoService;

    /**
     * 查询备忘录列表
     */
    @PreAuthorize("@ss.hasPermi('crmsys:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustNoticeInfo custNoticeInfo)
    {
        startPage();
        List<CustNoticeInfo> list = custNoticeInfoService.selectCustNoticeInfoList(custNoticeInfo);
        return getDataTable(list);
    }

    /**
     * 导出备忘录列表
     */
    @PreAuthorize("@ss.hasPermi('crmsys:notice:export')")
    @Log(title = "备忘录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustNoticeInfo custNoticeInfo)
    {
        List<CustNoticeInfo> list = custNoticeInfoService.selectCustNoticeInfoList(custNoticeInfo);
        ExcelUtil<CustNoticeInfo> util = new ExcelUtil<CustNoticeInfo>(CustNoticeInfo.class);
        util.exportExcel(response, list, "备忘录数据");
    }

    /**
     * 获取备忘录详细信息
     */
    @PreAuthorize("@ss.hasPermi('crmsys:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(custNoticeInfoService.selectCustNoticeInfoById(id));
    }

    /**
     * 新增备忘录
     */
    @Log(title = "备忘录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustNoticeInfo custNoticeInfo)
    {
        custNoticeInfo.setCreateBy(getLoginUser().getUserId().toString());
        custNoticeInfo.setCreateTime(DateUtils.getNowDate());
        custNoticeInfo.setStatus(StatusConstant.CUST_NOTICE_STATUS_NO);
        return toAjax(custNoticeInfoService.insertCustNoticeInfo(custNoticeInfo));
    }

    /**
     * 修改备忘录
     */
    @PreAuthorize("@ss.hasPermi('crmsys:notice:edit')")
    @Log(title = "备忘录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustNoticeInfo custNoticeInfo)
    {
        return toAjax(custNoticeInfoService.updateCustNoticeInfo(custNoticeInfo));
    }

    /**
     * 删除备忘录
     */
    @PreAuthorize("@ss.hasPermi('crmsys:notice:remove')")
    @Log(title = "备忘录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(custNoticeInfoService.deleteCustNoticeInfoByIds(ids));
    }
}
